package servlet;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import mapper.ListDate;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/main")
public class mainServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-Type", "text/html;charset=utf-8");
        JSONObject listDate = new ListDate().ListCP();
        response.getWriter().write(JSON.toJSONString(listDate));
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession httpsession = request.getSession();
        if (httpsession.getAttribute("QHB") == "QhbandLy1221"){
            request.getRequestDispatcher("html/main.html").forward(request,response);
        }else {
            response.sendRedirect("login");
        }

    }
}
